"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
exports.__esModule = true;
exports.DynamicRoutes = void 0;
var vue_router_1 = require("vue-router");
var index_1 = require("@/store/index");
//进度条
var nprogress_1 = require("nprogress");
require("nprogress/nprogress.css");
var routes = [
    {
        path: "/login",
        name: "login",
        component: function () { return Promise.resolve().then(function () { return require("@/views/login/login.vue"); }); }
    },
];
var router = (0, vue_router_1.createRouter)({
    history: (0, vue_router_1.createWebHashHistory)(),
    routes: routes
});
router.beforeEach(function (to, from, next) {
    nprogress_1["default"].start();
    //未登陆
    if (!window.localStorage.getItem("token") && to.path !== "/login") {
        return next({ path: "/login" });
    }
    ;
    //已登陆
    if (window.localStorage.getItem("token") && to.path == "/login")
        return next({ path: "/" });
    //重新加载动态路由
    if (!index_1["default"].state.permissionList && to.path != '/login') {
        // router.removeRoute('router');
        return index_1["default"].dispatch("FETCH_PERMISSION").then(function () {
            next(__assign(__assign({}, to), { replace: true }));
        });
    }
    else {
        next();
    }
});
router.afterEach(function (to, from, next) {
    nprogress_1["default"].done();
    try {
        //设置标题
        if (to.meta.name) {
            document.title = to.meta.name;
        }
    }
    catch (err) { }
    var routerList = to.matched;
    //顶部面包屑
    index_1["default"].commit("setCrumbList", routerList);
    //目前左边导航选中的active
    index_1["default"].commit("SET_CURRENT_MENU", to.name);
});
/* 固定的路由 */
/*
    meta:{
        name:侧边栏名字,
        icon:侧边栏图标,
        hide:是否在侧边栏隐藏
    }
*/
exports.DynamicRoutes = [
    {
        path: "",
        component: function () { return Promise.resolve().then(function () { return require("@/components/nav/nav.vue"); }); },
        name: "container",
        // redirect: 'home',
        meta: {
            // requiresAuth: true,
            name: "首页"
        },
        children: [
            {
                path: "home",
                component: function () { return Promise.resolve().then(function () { return require("@/views/home/home.vue"); }); },
                name: "home",
                meta: {
                    name: "首页",
                    icon: "el-icon-s-home"
                }
            },
            {
                path: "router",
                component: function () { return Promise.resolve().then(function () { return require("@/views/router/router.vue"); }); },
                name: "router",
                meta: {
                    name: "路由管理",
                    icon: "el-icon-guide",
                    hide: false
                }
            },
            {
                path: "color",
                component: function () { return Promise.resolve().then(function () { return require("@/views/color/color.vue"); }); },
                name: "color",
                meta: {
                    name: "主题管理",
                    icon: "el-icon-brush"
                }
            },
            {
                path: "language",
                component: function () { return Promise.resolve().then(function () { return require("@/views/language/language.vue"); }); },
                name: "language",
                meta: {
                    name: "国际化",
                    icon: "el-icon-s-flag"
                }
            },
            {
                path: "icon",
                component: function () { return Promise.resolve().then(function () { return require("@/views/icon/index.vue"); }); },
                name: "icon",
                meta: {
                    name: "图标管理",
                    icon: "el-icon-picture-outline-round"
                },
                children: [
                    {
                        path: "elicon",
                        component: function () { return Promise.resolve().then(function () { return require("@/views/icon/el-icon.vue"); }); },
                        name: "elicon",
                        meta: {
                            name: "Element图标",
                            icon: "el-icon-caret-bottom"
                        }
                    },
                    {
                        path: "aliicon",
                        component: function () { return Promise.resolve().then(function () { return require("@/views/icon/ali-icon.vue"); }); },
                        name: "aliicon",
                        meta: {
                            name: "阿里图标",
                            icon: "el-icon-caret-top"
                        }
                    }
                ]
            },
            {
                path: "table",
                component: function () { return Promise.resolve().then(function () { return require("@/views/table/index.vue"); }); },
                name: "table",
                meta: {
                    name: "表格管理",
                    icon: "el-icon-s-grid"
                },
                children: [
                    {
                        path: "basics",
                        component: function () { return Promise.resolve().then(function () { return require("@/views/table/basics.vue"); }); },
                        name: "basics",
                        meta: {
                            name: "基础表格",
                            icon: "el-icon-menu"
                        }
                    },
                    {
                        path: "complex",
                        component: function () { return Promise.resolve().then(function () { return require("@/views/table/complex.vue"); }); },
                        name: "complex",
                        meta: {
                            name: "复杂表格",
                            icon: "el-icon-s-grid"
                        }
                    }
                ]
            },
            {
                path: "chart",
                component: function () { return Promise.resolve().then(function () { return require("@/views/chart/index.vue"); }); },
                name: "chart",
                meta: {
                    name: "图表示例",
                    icon: "el-icon-s-data"
                },
                children: [
                    {
                        path: "column",
                        component: function () { return Promise.resolve().then(function () { return require("@/views/chart/column.vue"); }); },
                        name: "column",
                        meta: {
                            name: "柱形图表",
                            icon: "el-icon-s-data"
                        }
                    },
                    {
                        path: "line",
                        component: function () { return Promise.resolve().then(function () { return require("@/views/chart/line.vue"); }); },
                        name: "line",
                        meta: {
                            name: "折线图表",
                            icon: "el-icon-minus"
                        }
                    },
                    {
                        path: "more",
                        component: function () { return Promise.resolve().then(function () { return require("@/views/chart/more.vue"); }); },
                        name: "more",
                        meta: {
                            name: "其他图表",
                            icon: "el-icon-s-operation"
                        }
                    },
                ]
            },
            {
                path: "text",
                component: function () { return Promise.resolve().then(function () { return require("@/views/text/text.vue"); }); },
                name: "text",
                meta: {
                    name: "富文本编辑器",
                    icon: "el-icon-document"
                }
            },
            {
                path: "uploading",
                component: function () { return Promise.resolve().then(function () { return require("@/views/uploading/uploading.vue"); }); },
                name: "uploading",
                meta: {
                    name: "自定义图片上传",
                    icon: "el-icon-upload"
                }
            },
            {
                path: "map",
                component: function () { return Promise.resolve().then(function () { return require("@/views/map/index.vue"); }); },
                name: "map",
                meta: {
                    name: "地图",
                    icon: "el-icon-map-location"
                },
                children: [
                    {
                        path: "baidu",
                        component: function () { return Promise.resolve().then(function () { return require("@/views/map/baidu.vue"); }); },
                        name: "baidu",
                        meta: {
                            name: "百度地图",
                            icon: "el-icon-guide"
                        }
                    },
                    {
                        path: "autoNavi",
                        component: function () { return Promise.resolve().then(function () { return require("@/views/map/autoNavi.vue"); }); },
                        name: "autoNavi",
                        meta: {
                            name: "高德地图",
                            icon: "el-icon-position"
                        }
                    }
                ]
            },
            {
                path: "contact",
                component: function () { return Promise.resolve().then(function () { return require("@/views/contact/contact.vue"); }); },
                name: "contact",
                meta: {
                    name: "联系我们",
                    icon: "el-icon-phone"
                }
            },
            {
                path: "else",
                component: function () { return Promise.resolve().then(function () { return require("@/views/else/index.vue"); }); },
                name: "else",
                meta: {
                    name: "其他组件",
                    icon: "el-icon-question"
                },
                children: [
                    {
                        path: "convas",
                        component: function () { return Promise.resolve().then(function () { return require("@/views/else/canvas.vue"); }); },
                        name: "convas",
                        meta: {
                            name: "页面生成图片",
                            icon: "el-icon-picture-outline"
                        }
                    },
                    {
                        path: "code",
                        component: function () { return Promise.resolve().then(function () { return require("@/views/else/code.vue"); }); },
                        name: "code",
                        meta: {
                            name: "动态二维码",
                            icon: "el-icon-full-screen"
                        }
                    }
                ]
            }
        ]
    }
];
exports["default"] = router;
